import { createRouter, createWebHistory } from "vue-router";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/login",
      name: "login",
      component: () => import("@/views/login/index.vue"),
    },
    {
      path: "/register",
      name: "register",
      component: () => import("@/views/register/index.vue"),
    },
    ,
  ],
});

export default router;

export const addRoute = (roles: string = "ROLE_EMPLOYEE") => {
  if (roles === "ROLE_ADMIN") {
    router.addRoute({
      path: "/",
      name: "home",
      component: () => import("@/views/home/index.vue"),
      redirect: "/home",
      children: [
        {
          path: "home",
          component: () => import("@/views/homePage/index.vue"),
        },
        {
          path: "attractions",
          component: () => import("@/views/attractions/index.vue"),
        },
        {
          path: "employee",
          component: () => import("@/views/employee/index.vue"),
        },
        {
          path: "/itinerary",
          component: () => import("@/views/itinerary/index.vue"),
        },
      ],
    });
  } else {
    router.addRoute({
      path: "/",
      name: "home",
      component: () => import("@/views/home/index.vue"),
      redirect: "/home",
      children: [
        {
          path: "home",
          component: () => import("@/views/homePage/index.vue"),
        },
        {
          path: "attractions",
          component: () => import("@/views/attractions/index.vue"),
        },

        {
          path: "itinerary",
          component: () => import("@/views/itinerary/index.vue"),
        },
      ],
    });
  }
};
